//
//  homeViewController.m
//  YuErmuYing
//
//  Created by Tiancheng on 16/8/8.
//  Copyright © 2016年 Tiancheng. All rights reserved.
//

#import "homeViewController.h"
#import "Macros.h"
#import "UIColor+RandomColor.h"
#import "HttpRequest.h"
#import "xianXiaHuoDongViewController.h"
#import "cuiRuShiViewController.h"
#import "xinShengErHuLiViewController.h"
#import "yueShaoViewController.h"
#import "baoMaShangChengViewController.h"
#import "yiYuanDuoBaoViewController.h"
#import "shaiDanViewController.h"
#import "jiFenDuiHuanViewController.h"
#import "UIImageView+WebCache.h"
#import "renQi.h"
//判断跳转界面(是跳转到催乳师,还是月嫂的界面)
#import "tiaoZhuanView.h"
//抢宝的Model
#import "qiangBao.h"
#import "babySwimViewController.h"
#import "swimToPhoto.h"
#import "postPhotoViewController.h"
#import "shaiDan.h"
#import "changeNinaPagerViewHeight.h"
#import "newYiYuanDuoBaoViewController.h"
#import "NSString+NSDateToNSString.h"
#import "WeakTimer.h"
#import "yiYuanDuoBao.h"
#import "goodsDetailViewController.h"
#import "yiYuanDuoBaoNextView.h"
#import "zuiXinJieXiaoViewController.h"
//跳转至积分商城
#import "TCLYIntergralViewController.h"
//跳转至宝妈商城
#import "TCLYBabyHomeViewController.h"
//请求数据的Model
#import "TCLYHomeModel.h"
#import "TCLYUser.h"

#import "TCLYUser.h"
#import "TCLYLoginViewController.h"

#import "adDetailViewController.h"
#import "adModel.h"
#import "BHInfiniteScrollView.h"
//轮播图片
#import "LO_CarouselFigure.h"


@interface homeViewController ()<UIScrollViewDelegate,BHInfiniteScrollViewDelegate>
//标头栏
@property (weak, nonatomic) IBOutlet UIView *headerView;
@property (weak, nonatomic) IBOutlet UIScrollView *backGroundScrollView;
@property (weak, nonatomic) IBOutlet UIView *backGroundView;
//图片的轮播图
@property (weak, nonatomic) IBOutlet UIScrollView *imageScrollView;
@property(nonatomic,retain)UIPageControl*upc;

//八个按钮小的方块长度
@property(nonatomic,assign)float smallWidth;
//八个按钮
@property(nonatomic,retain)UIButton *picButton;
//通过数组来获得第二行按钮的图片的位置
@property(nonatomic,copy)NSMutableArray *pic_Array;
//长条背景图
@property(nonatomic,copy)UIView *uview0;
//喇叭里的滚动字幕
@property(nonatomic,retain)UILabel *laBarLabel1;
//喇叭的view
@property(nonatomic,retain)UIView*next_view;
//在一元夺宝中从数组里获取四个数值
@property(nonatomic,copy)NSMutableArray *json_Array1;
//一元抢宝,马上揭晓
@property(nonatomic,retain)UIView*next_uview1;
//一元夺宝,四个小界面里的图片
@property(nonatomic,retain)UIImageView *duoBaoImageView1;
//一元夺宝,四个小界面里的名字
@property(nonatomic,retain)UILabel *namelabel;
//一元夺宝,四个小界面里的时间1
@property(nonatomic,retain)UILabel *timeLabel1;
//一元夺宝,四个小界面里的时间3
@property(nonatomic,retain)UILabel *timeLabel3;
//创建可变数组用来接收,一元夺宝的四个小界面。
@property(nonatomic,copy)NSMutableArray *duoBaoViewArray;
//存放人气推荐的数组
@property(nonatomic,copy)NSMutableArray*json_Array2;
//人气推荐灰色边框
@property(nonatomic,retain)UIView *view22;
//目前现有的人数
@property(nonatomic,retain)UILabel*nowPeopleLabel2;
//通过人气推荐的数组来确定出最后的总高度
@property(nonatomic,copy)NSMutableArray *renQiArray;
//装人气id Array
@property(nonatomic,copy)NSMutableArray *renQiIDArray;

//夺宝的view
@property(nonatomic,retain)UIView *duoBaoView;
//@property(nonatomic,assign)int num;
@property(nonatomic,copy)NSMutableArray *labelArray;
@property(nonatomic,copy)NSMutableArray *timeArray;

@property(nonatomic,assign)int timerNumber1;
@property(nonatomic,assign)int timerNumber2;
@property(nonatomic,assign)int timerNumber3;
@property(nonatomic,assign)int timerNumber4;

@property(nonatomic,retain)NSTimer *timer1;
@property(nonatomic,retain)NSTimer *timer2;
@property(nonatomic,retain)NSTimer *timer3;
@property(nonatomic,retain)NSTimer *timer4;
//更新获奖名单的名字
@property(nonatomic,retain)NSTimer *timer5;

@property(nonatomic,copy)NSMutableArray *idArray;

//定时器
@property (nonatomic, strong) dispatch_source_t lytimer;
@property (nonatomic, strong) TCLYHomeModel * lyHomeModel;
@property (nonatomic, strong) TCLYLoginViewController * loginViewCtr;
//创建轮播图的数组
@property(nonatomic,copy)NSMutableArray *lunBoTuArray;
//轮播的计时器,让视图自动切换
@property (nonatomic, retain)NSTimer* rotateTimer;
//字典存储cid的值
@property (nonatomic, retain)NSMutableDictionary* numDiction;
@property(nonatomic,retain)UIImageView *anotherTempImageView;
//图片的数组
@property(nonatomic,copy)NSMutableArray*picMutableArray;
//cid
@property(nonatomic,copy)NSMutableArray*cidMutableArray;
@property(nonatomic,assign)float viewHeight;
@end

@implementation homeViewController
@synthesize pic_Array,uview0,imageScrollView,upc,next_view,json_Array1,next_uview1,duoBaoImageView1,namelabel,timeLabel1,timeLabel3,duoBaoViewArray,json_Array2,view22,nowPeopleLabel2,renQiArray,duoBaoView,labelArray,timeArray,timer1,timer2,timer3,timer4,idArray,renQiIDArray,timer5,lunBoTuArray,numDiction,picMutableArray,cidMutableArray,viewHeight;
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBarHidden=YES;
    self.tabBarController.tabBar.hidden=NO;

}
-(void)login{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logins) name:@"login" object:nil];
    self.loginViewCtr = [[TCLYLoginViewController alloc] init];
    [self presentViewController:self.loginViewCtr animated:YES completion:nil];
}
-(void)logins{
    [self.loginViewCtr dismissViewControllerAnimated:YES completion:nil];
    [self newsPrompt];
}
- (void)viewDidLoad
{
    
    [super viewDidLoad];
    self.headerView.backgroundColor=[UIColor colorWithRed:244/255.0 green:142/255.0 blue:177/255.0 alpha:1];
    self.smallWidth=screenWidth/4;
    json_Array2=[NSMutableArray array];
    renQiArray=[NSMutableArray array];
    labelArray=[NSMutableArray array];
    timeArray=[NSMutableArray array];
    idArray=[NSMutableArray array];
    renQiIDArray=[NSMutableArray array];
    lunBoTuArray=[NSMutableArray array];
    picMutableArray=[NSMutableArray array];
    cidMutableArray=[NSMutableArray array];
    //调用轮播接口
    [self createLunBoTu];
//   创建8个按钮
    [self createEightButton];

//    创建人气推荐界面
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateRenQiTuiJian) name:@"updateRenQiTuiJian" object:nil];
    shaiDan *sd=[shaiDan shardeManager];
    sd.whichViewToBack=0;
//    [self cretaeAAAA];
    //客户要求来新的消息时候会显示消息数量 并且该项目没有实时通讯以及消息推送功能 只是通过接口向后台请求数据 用计时器定时间向后台请求一次
    [self login];
}
//创建8个按钮
-(void)createEightButton
{
    //**********************************************
    //创建轮播图
//    [self  createHeaderScrollCiew];
    //*********************************************
    pic_Array=[NSMutableArray array];
    json_Array1=[NSMutableArray array];
    duoBaoViewArray=[NSMutableArray array];
    //八个按钮的图片名字
    NSArray *picArray=[NSArray arrayWithObjects:@"youWenBiDa",@"cuiRuShi",@"xinShengErHuLi",@"yueShao", @"baoMaShangCheng",@"yiYuanDuoBao",@"shaiDan",@"exchange",nil];
    //八个按钮的文字
    NSArray *picNameArray=[NSArray arrayWithObjects:@"小岛商家",@"催乳师",@"二手闲置",@"月嫂",@"宝妈商城",@"一元夺宝",@"晒单",@"积分兑换", nil];
    for (int i=0; i<2; i++)
    {
        for (int j=0; j<4; j++)
        {
            //20=0.0534*screenWidth
            self.picButton=[[UIButton alloc]initWithFrame:CGRectMake(self.smallWidth*j, (self.smallWidth-0.0534*screenWidth)*i+140, self.smallWidth, self.smallWidth-0.0534*screenWidth)];
            self.picButton.tag=j+i*4;
            self.picButton.backgroundColor=[UIColor whiteColor];
            [self.picButton addTarget:self action:@selector(onClick1:) forControlEvents:UIControlEventTouchUpInside];
            [self.backGroundView addSubview:self.picButton];
            //25=0.0667*screenWidth
            //5=0.0133*screenWidth
            //40=0.1067*screenWidth
            UIImageView *pic_ImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0.0667*screenWidth, 0.0133*screenWidth, 0.1067*screenWidth, 0.1067*screenWidth)];
            pic_ImageView.image=[UIImage imageNamed:picArray[j+i*4]];
            [self.picButton addSubview:pic_ImageView];
            //15＝0.04*screenWidth
            //50＝0.1333*screenWidth
            //60＝0.16*screenWidth
            //20＝0.0533*screenWidth
            UILabel *picLabel=[[UILabel alloc]initWithFrame:CGRectMake(0.015*screenWidth, 0.1333*screenWidth,0.2133*screenWidth,0.0533*screenWidth)];
            picLabel.textAlignment=NSTextAlignmentCenter;
        //0.04*screenWidth,0.16*screenWidth
//            picLabel.backgroundColor=[UIColor whiteColor];
            picLabel.text=picNameArray[j+i*4];
            picLabel.textColor=[UIColor colorWithRed:216/255.0 green:27/255.0 blue:96/255.0 alpha:1];
            picLabel.font=[UIFont systemFontOfSize:15];
            //字体居中
            picLabel.textAlignment=NSTextAlignmentCenter;
            [self.picButton addSubview:picLabel];
            [pic_Array addObject:self.picButton];
        }
    }
    if (pic_Array[4])
    {
        [self createActiveButton];
    }
}
//轮播图的接口
-(void)createLunBoTu
{
    //网络请求
    NSString *urlString=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/api/Carousel/carousel"];
    HttpRequest *httpRequest=[HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlString parameters:nil success:^(id responseObject)
     {
         id json = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         //获取数组
         lunBoTuArray=[json objectForKey:@"data"];
//         NSLog(@"lunBoTuArray=%@",lunBoTuArray);
         if (lunBoTuArray.count>0)
         {
             for (int i=0; i<lunBoTuArray.count; i++)
             {
                 NSString *picString=[lunBoTuArray[i] objectForKey:@"pic"];
                 [picMutableArray addObject:picString];
                 NSString *cidString=[lunBoTuArray[i] objectForKey:@"cid"];
                 [cidMutableArray addObject:cidString];
             }
             if (picMutableArray.count==lunBoTuArray.count)
             {
                 
                  [self createHeaderScrollCiew];
             }
         }
//         for (<#initialization#>; <#condition#>; <#increment#>) {
//             <#statements#>
//         }
         
//         if (lunBoTuArray.count>0)
//         {
//             [self createHeaderScrollCiew];
//         }
//         NSLog(@"json=%@",json);
     } failure:^(NSError *error) {
         NSLog(@"error=%@",error);
     }];
}
//创建轮播图
-(void)createHeaderScrollCiew
{
    LO_CarouselFigure *cf = [[LO_CarouselFigure alloc]initWithFrame:CGRectMake(0, 0,screenWidth,140)];
    //设置轮播时间
    cf.carouselTime = 2;
    //设置占位图
    cf.bitmapImage = [UIImage imageNamed:@"banner"];
    //给URLstring数组
    cf.sd_URLArray = picMutableArray;
    //添加到view上
    [self.backGroundView addSubview:cf];
    //添加点击时方法
    [cf addTouchImageActionBlock:^(NSInteger index) {
        int num=(int)index;
        NSString *cidString=cidMutableArray[num];
        adModel*adm=[adModel sharedManager];
        adm.cidString=cidString;
        adDetailViewController *advc=[adDetailViewController new];
        [self.navigationController pushViewController:advc animated:YES];
    }];
    
    
    
    
    
    
    
    
    
    
//    viewHeight = [UIScreen mainScreen].bounds.size.height/4;
//    BHInfiniteScrollView* infinitePageView1 = [BHInfiniteScrollView
//                                               infiniteScrollViewWithFrame:CGRectMake(0,0,CGRectGetWidth(self.view.frame), 140) Delegate:self ImagesArray:picMutableArray];
//    infinitePageView1.pageControlAlignmentOffset = CGSizeMake(0, 20);
//    infinitePageView1.scrollTimeInterval = 2;
//    infinitePageView1.autoScrollToNextPage = YES;
//    infinitePageView1.delegate = self;
//    infinitePageView1.reverseDirection = NO;
//    infinitePageView1.contentMode=UIViewContentModeCenter;
//    infinitePageView1.placeholderImage=[UIImage imageNamed:@"banner"];
//    [self.backGroundView addSubview:infinitePageView1];
//    NSMutableArray *urlarr = [NSMutableArray array];
//    for (NSString *str in picMutableArray)
//    {
//        NSURL *imurl = [NSURL URLWithString:str];
//        [urlarr addObject:imurl];
//    }
//    UIImage *placeholder = [UIImage imageNamed:@"banner"];
//    ZLScrolling *zl = [[ZLScrolling alloc] initWithCurrentController:self frame:CGRectMake(0, 0, screenWidth, 140) photos:urlarr placeholderImage:placeholder];
//    ZLScrolling *zl = [[ZLScrolling alloc]initWithCurrentController:self frame:CGRectMake(0, 0, screenWidth, 140) photos:urlarr placeholderImage:placeholder SubView:self.backGroundView];

//  zl.timeInterval = 2;
    //    zl.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
//    zl.delegate= self;
//        [self.backGroundView addSubview:zl];


//    CGSize size=CGSizeMake(screenWidth*5, 0);
//    imageScrollView.contentSize=size;
//    //设置分页效果
//    imageScrollView.pagingEnabled = YES;
//    imageScrollView.delegate=self;
//    imageScrollView.showsHorizontalScrollIndicator=NO;
//    imageScrollView.showsVerticalScrollIndicator=NO;
//    //创建字典
//    numDiction=[NSMutableDictionary dictionary];
//    for (int i=0; i<5; i++)
//    {
//        UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(screenWidth*i, 0, screenWidth, 140)];
//        NSString *numString=[lunBoTuArray[i] objectForKey:@"cid"];
//        imgView.tag=1000+i;
//        NSString *tagString=[NSString stringWithFormat:@"%ld",imgView.tag];
//        [numDiction setObject:numString forKey:tagString];
//        
//        NSString *str=[lunBoTuArray[i] objectForKey:@"pic"];
//        NSURL* imagePath = [NSURL URLWithString:str];
////        //给一张默认图片，先使用默认图片，当图片加载完成后再替换
////        [imgView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"banner"]];
//        [imgView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"banner"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
//        {
//            nil;
//        }];
//        //添加手势
//        UITapGestureRecognizer *tap=[[UITapGestureRecognizer  alloc ] initWithTarget:self action : @selector (GoodsDetailInformation:)];
//        imgView.userInteractionEnabled=YES;
//        [imgView addGestureRecognizer:tap];
//        
//        [imageScrollView addSubview:imgView];
//        
//       
//    }
//    UIImageView *tempImageView=[imageScrollView viewWithTag:1000];
////    NSString *tempString=[lunBoTuArray[0] objectForKey:@"pic"];
////    NSURL* imagePath01 = [NSURL URLWithString:tempString];
////    //        //给一张默认图片，先使用默认图片，当图片加载完成后再替换
////    [tempImageView sd_setImageWithURL:imagePath01 placeholderImage:[UIImage imageNamed:@"banner1"]];
////    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
////    tempImageView.image=self.anotherTempImageView.image;
//    //为滚动视图的右边添加一个视图，使得它和第一个视图一模一样。
//    UIImageView *sixImageView=[[UIImageView alloc]initWithFrame:CGRectMake(screenWidth*5, 0, screenWidth, 140)];
//    sixImageView.image=tempImageView.image;
//    [imageScrollView addSubview:sixImageView];
//
//    upc=[[UIPageControl alloc]initWithFrame:CGRectMake((screenWidth-0.4*screenWidth)/2, 90, 0.4*screenWidth, 66)];
//    upc.numberOfPages=5;
//    upc.currentPage=0;
//    [self.backGroundView addSubview:upc];
//    imageScrollView.tag = 1000;
//
//    //启动定时器
//    self.rotateTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeView) userInfo:nil repeats:YES];
}
//- (void)infiniteScrollView:(BHInfiniteScrollView *)infiniteScrollView didSelectItemAtIndex:(NSInteger)index
//{
//    int num=(int)index;
//    NSString *cidString=cidMutableArray[num];
//    adModel*adm=[adModel sharedManager];
//    adm.cidString=cidString;
//    adDetailViewController *advc=[adDetailViewController new];
//    [self.navigationController pushViewController:advc animated:YES];
//}

//- (void)zlScrolling:(ZLScrolling *)zlScrolling clickAtIndex:(NSInteger)index
//{
//    NSLog(@"123");
//    NSLog(@"点击到------%ld",index);
//
//
//}
//#pragma mark -- 滚动视图的代理方法
////开始拖拽的代理方法，在此方法中暂停定时器。
//-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
//{
//    NSLog(@"正在拖拽视图，所以需要将自动播放暂停掉");
//    //setFireDate：设置定时器在什么时间启动
//    //[NSDate distantFuture]:将来的某一时刻
//    [self.rotateTimer setFireDate:[NSDate distantFuture]];
//}
////视图静止时（没有人在拖拽），开启定时器，让自动轮播
//-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
//{
//    //视图静止之后，过1.5秒在开启定时器
//    //[NSDate dateWithTimeInterval:1.5 sinceDate:[NSDate date]]  返回值为从现在时刻开始 再过1.5秒的时刻。
//    NSLog(@"开启定时器");
//    [self.rotateTimer setFireDate:[NSDate dateWithTimeInterval:1.5 sinceDate:[NSDate date]]];
////    upc.currentPage=scrollView.contentOffset.x/screenWidth;
//}
////定时器的回调方法   切换界面
//- (void)changeView
//{
//    //得到scrollView
//    UIScrollView *scrollView = [self.view viewWithTag:1000];
//    //通过改变contentOffset来切换滚动视图的子界面
//    float offset_X = scrollView.contentOffset.x;
//    //每次切换一个屏幕
//    offset_X += CGRectGetWidth(self.view.frame);
//    //说明要从最右边的多余视图开始滚动了，最右边的多余视图实际上就是第一个视图。所以偏移量需要更改为第一个视图的偏移量。
//    if (offset_X > CGRectGetWidth(self.view.frame)*5)
//    {
//        scrollView.contentOffset = CGPointMake(0, 0);
//        
//    }
//    //说明正在显示的就是最右边的多余视图，最右边的多余视图实际上就是第一个视图。所以pageControl的小白点需要在第一个视图的位置。
//    if (offset_X == CGRectGetWidth(self.view.frame)*5)
//    {
//        self.upc.currentPage = 0;
//    }else{
//        self.upc.currentPage = offset_X/CGRectGetWidth(self.view.frame);
//    }
//    //得到最终的偏移量
//    CGPoint resultPoint = CGPointMake(offset_X, 0);
//    //切换视图时带动画效果
//    //最右边的多余视图实际上就是第一个视图，现在是要从第一个视图向第二个视图偏移，所以偏移量为一个屏幕宽度
//    if (offset_X >CGRectGetWidth(self.view.frame)*5)
//    {
//        self.upc.currentPage = 1;
//        [scrollView setContentOffset:CGPointMake(CGRectGetWidth(self.view.frame), 0) animated:YES];
//    }
//    else
//    {
//        [scrollView setContentOffset:resultPoint animated:YES];
//    }
//    
//}

//-(void)GoodsDetailInformation:(UITapGestureRecognizer*)sender
//{
//    adModel*adm=[adModel sharedManager];
//    NSString *str=[NSString stringWithFormat:@"%ld",sender.view.tag];
//    NSString *str1=[numDiction objectForKey:str];
//    adm.cidString=str1;
//    adDetailViewController *advc=[adDetailViewController new];
//    [self.navigationController pushViewController:advc animated:YES];
//}

//创建活动专区的界面
-(void)createActiveButton
{
   UIButton *btn=pic_Array[4];
   float btn_y=btn.frame.origin.y+self.smallWidth-0.0534*screenWidth;
    //119=0.3174*screenWidth
    uview0=[[UIView alloc]initWithFrame:CGRectMake(0, btn_y, screenWidth, 0.3174*screenWidth)];
    uview0.backgroundColor=[UIColor whiteColor];
    [self.backGroundView addSubview:uview0];
    //灰色背景框
    //18=0.048*screenWidth
    UIView *uview1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 0.048*screenWidth)];
    uview1.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
    [uview0 addSubview:uview1];
    //2=0.00533*screenWidth
    //100=0.2667*screenWidth
    //11=0.02934*screenWidth
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0.00533*screenWidth,0.2667*screenWidth, 0.02934*screenWidth)];
    label.text=@"活动专区";
    label.textColor=[UIColor blackColor];
    label.font=[UIFont systemFontOfSize:15];
    [uview1 addSubview:label];
    NSArray *picArray1=[NSArray arrayWithObjects:@"xinRenDuoBao",@"baoBaoTiYanZhao",@"yingErYouYongTiYan",@"chuanZhaoPianYingJiangPin", nil];
    for (int i=0; i<2; i++)
    {
        for (int j=0; j<2; j++)
        {
            //18=0.048*screenWidth
            //50.5=0.13467*screenWidth
            UIImageView *picImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0+j*screenWidth/2, 0.048*screenWidth+0.13467*screenWidth*i, screenWidth/2, 0.13467*screenWidth)];
            picImageView.tag=j+i*2;
            picImageView.image=[UIImage imageNamed:picArray1[j+i*2]];
            [uview0 addSubview:picImageView];
            //添加手势
            UITapGestureRecognizer *tap=[[UITapGestureRecognizer  alloc ] initWithTarget:self action : @selector (onClick2:)];
            picImageView.userInteractionEnabled=YES;
            [picImageView addGestureRecognizer:tap];
        }
    }
    if (uview0)
    {
        [self createScrollLabel];
    }
    
}
//创建滚动字幕
-(void)createScrollLabel
{
    float uview_y=uview0.frame.origin.y+0.3174*screenWidth;
    next_view=[[UIView alloc]initWithFrame:CGRectMake(0, uview_y, screenWidth, 23)];
    next_view.backgroundColor=[UIColor whiteColor];
    [self.backGroundView addSubview:next_view];
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(20, 2,18, 18)];
    imageView.image=[UIImage imageNamed:@"laBa"];
    [next_view addSubview:imageView];
    
    //滚动字幕的计时器
    timer5=[WeakTimer scheduledTimerWithTimeInterval:2.0f block:^(id userInfo)
            {
                [self changeNum0];
            } userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer5 forMode:NSDefaultRunLoopMode];
    
    self.laBarLabel1=[[UILabel alloc]initWithFrame:CGRectMake(71, 2, 100, 15)];
    NSString *s=@"初六的妈妈";
//    self.laBarLabel1.text=@"初六的妈妈";
    self.laBarLabel1.textColor=[UIColor blackColor];
    self.laBarLabel1.font=[UIFont systemFontOfSize:14];
//    self.laBarLabel1.backgroundColor=[UIColor orangeColor];
    //*******************************************
    //可以换行
    [self.laBarLabel1 setNumberOfLines:0];
    CGSize size = CGSizeMake(320,2000);
    CGSize labelsize = [s sizeWithFont:self.laBarLabel1.font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
    [self.laBarLabel1 setFrame:CGRectMake(0.1867*screenWidth,2, labelsize.width, labelsize.height)];
    self.laBarLabel1.textAlignment=NSTextAlignmentLeft;
    [next_view addSubview:self.laBarLabel1];
    //创建一元夺宝的活动界面
    [self createYiYuanDuoBao];
    
}
-(void)changeNum0
{
    [UIView animateWithDuration:2.0 animations:^{
        self.laBarLabel1.text=@"初六的妈妈";
        self.laBarLabel1.alpha=0.0;
        self.laBarLabel1.frame=CGRectMake(71, -10, 100, 15);
    } completion:^(BOOL finished) {
//        [dataArray01 removeObjectAtIndex:0];
//        [dataArray01 addObject:@"51"];
        //71, 2, 100, 15
        self.laBarLabel1.text=@"初六的妈妈";
        self.laBarLabel1.alpha=1.0;
        self.laBarLabel1.frame=CGRectMake(71, 2, 100, 15);
    }];


}
//创建一元夺宝的活动界面
-(void)createYiYuanDuoBao
{
    float uview_y1=next_view.frame.origin.y+23;
    next_uview1=[[UIView alloc]initWithFrame:CGRectMake(0, uview_y1, screenWidth, 0.064*screenWidth)];
    next_uview1.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
    [self.backGroundView addSubview:next_uview1];
    UILabel *label1=[[UILabel alloc]initWithFrame:CGRectMake(0.0533*screenWidth, 2, 200, 20)];
    label1.text=@"一元抢宝一马上揭晓";
    label1.textColor=[UIColor colorWithRed:216/255.0 green:29/255.0 blue:96/255.0 alpha:1.0];
    [next_uview1 addSubview:label1];
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(screenWidth-0.2133*screenWidth, 2, 80, 20)];
    [btn setTitle:@"更多" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor colorWithRed:216/255.0 green:29/255.0 blue:96/255.0 alpha:1.0] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onClick3:) forControlEvents:UIControlEventTouchUpInside];
    [next_uview1 addSubview:btn];
    //获取一元夺宝的时间,以及公布的界面
        [self updateYiYuanDuoBao];
   
}

//八个按钮的点击方法
-(void)onClick1:(UIButton*)sender
{
    NSInteger integer=sender.tag;
    int num=(int)integer;
    tiaoZhuanView *tzv=[tiaoZhuanView shardeManager];
    if (num==0)
    {
         changeNinaPagerViewHeight *cnpv=[changeNinaPagerViewHeight shardeManager];
        cnpv.NinaPagerViewHeight=64;
        xianXiaHuoDongViewController*xxhd=[xianXiaHuoDongViewController new];
        [self.navigationController pushViewController:xxhd animated:YES];
    }
    else if (num==1)
    {
        tzv.yueShao=0;
        yueShaoViewController *ysvc=[yueShaoViewController new];
        [self.navigationController pushViewController:ysvc animated:YES];
    }else if (num==2)
    {
        changeNinaPagerViewHeight *cnpv=[changeNinaPagerViewHeight shardeManager];
        cnpv.NinaPagerViewHeight=150;
        xinShengErHuLiViewController *xsehlvc=[xinShengErHuLiViewController new];
        [self.navigationController pushViewController:xsehlvc animated:YES];
    }else if (num==3)
    {
        tzv.yueShao=1;
        yueShaoViewController *ysvc=[yueShaoViewController new];
        [self.navigationController pushViewController:ysvc animated:YES];
        
    }else if (num==4)
    {
        TCLYBabyHomeViewController * babyHomeViewCtr = [[TCLYBabyHomeViewController alloc] init];
        [self.navigationController pushViewController:babyHomeViewCtr animated:YES];
    }else if (num==5)
    {
//        NSLog(@"一元夺宝");
        shaiDan *sd=[shaiDan shardeManager];
        sd.whichViewToBack=100;
        yiYuanDuoBaoViewController *ydbv=[yiYuanDuoBaoViewController new];
        [self.navigationController pushViewController:ydbv animated:YES];
    }else if (num==6)
    {
        shaiDan *sd=[shaiDan shardeManager];
        sd.whichViewToBack=0;
        shaiDanViewController *sdvc=[shaiDanViewController new];
        [self.navigationController pushViewController:sdvc animated:YES];
    }else if (num==7)
    {
//        jiFenDuiHuanViewController *jfdh=[jiFenDuiHuanViewController new];
//        [self.navigationController pushViewController:jfdh animated:YES];
        TCLYIntergralViewController * intergralViewCtr = [[TCLYIntergralViewController alloc] init];
        [self.navigationController pushViewController:intergralViewCtr animated:YES];
    }
}
//四个长条图片的点击方法
-(void)onClick2:(UITapGestureRecognizer *)sender
{
    NSInteger integer=sender.view.tag;
    int num=(int)integer;
    if (num==0)
    {
        newYiYuanDuoBaoViewController *nyydb=[newYiYuanDuoBaoViewController new];
        [self.navigationController pushViewController:nyydb animated:YES];
    }else if (num ==1)
    {
        swimToPhoto *stp=[swimToPhoto shardeManager];
        stp.num=1;
        babySwimViewController *bsvc=[babySwimViewController new];
        [self.navigationController pushViewController:bsvc animated:YES];
    }else if (num ==2)
    {
        swimToPhoto *stp=[swimToPhoto shardeManager];
        stp.num=2;
        babySwimViewController *bsvc=[babySwimViewController new];
        [self.navigationController pushViewController:bsvc animated:YES];
        
    }else if (num ==3)
    {
        postPhotoViewController *ppvc=[postPhotoViewController new];
        [self.navigationController pushViewController:ppvc animated:YES];
    }
}
//一元夺宝里的更多的按钮方法
-(void)onClick3:(UIButton*)sender
{
    yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
    yydb.whichViewToTheNext=1;
    zuiXinJieXiaoViewController *zxjv=[zuiXinJieXiaoViewController new];
    [self.navigationController pushViewController:zxjv animated:YES];
}
//一元夺宝更新四个
-(void)updateYiYuanDuoBao
{
    //网络请求
    NSString *urlString=[NSString stringWithFormat:@"http://112.74.114.1/parenting/index.php/api/Indiana/indiana"];
    HttpRequest *httpRequest=[HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlString parameters:nil success:^(id responseObject)
     {
         id json1 = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         //获取数组
         json_Array1=[json1 objectForKey:@"data"];
         [self createDuoBaoView];
//         NSLog(@"json1=%@",json1);
     } failure:^(NSError *error) {
         NSLog(@"error=%@",error);
     }];
}
//夺宝的界面里的四个小界面
-(void)createDuoBaoView
{
    if (json_Array1.count>0)
    {
        float uview1_y2=next_uview1.frame.origin.y+next_uview1.frame.size.height;
        qiangBao *qb=[qiangBao new];
        UIView *verticalLineView1=[[UIView alloc]initWithFrame:CGRectMake(screenWidth/2, uview1_y2+0.026667*screenWidth, 2, 0.36*screenWidth-0.05333*screenWidth)];
        verticalLineView1.backgroundColor=[UIColor colorWithRed:194/255.0 green:24/255.0 blue:91/255.0 alpha:0.8];
        [self.backGroundView addSubview:verticalLineView1];
        for (int i=0; i<2; i++)
        {
            for (int j=0; j<2; j++)
            {
                duoBaoView=[[UIView alloc]initWithFrame:CGRectMake(0+j*screenWidth/2+j+2*j, uview1_y2+i*0.18*screenWidth, screenWidth/2, 0.18*screenWidth)];
                duoBaoView.tag=j+2*i;
                //添加手势
                UITapGestureRecognizer *tap=[[UITapGestureRecognizer  alloc ] initWithTarget:self action : @selector (nextToGoodsDetail:)];
                duoBaoView.userInteractionEnabled=YES;
                [duoBaoView addGestureRecognizer:tap];
                duoBaoView.backgroundColor=[UIColor whiteColor];
                [self.backGroundView addSubview:duoBaoView];
                //把duoBaoView添加到duoBaoViewArray这个数组里
                [duoBaoViewArray addObject:duoBaoView];
                qb.duoBaoID=[json_Array1[j+i*2] objectForKey:@"id"];
                [idArray addObject:qb.duoBaoID];
                qb.name=[json_Array1[j+i*2] objectForKey:@"name"];
//                NSLog(@"qb.name=%@",qb.name);
                qb.picName=[json_Array1[j+i*2] objectForKey:@"pic"];
                qb.time=[json_Array1[j+i*2] objectForKey:@"time"];
//                NSLog(@"qb.time=%@",qb.time);
                [timeArray addObject:qb.time];
                qb.duoBaoID=[json_Array1[j+i*2] objectForKey:@"id"];
                namelabel=[[UILabel alloc]initWithFrame:CGRectMake(0.04*screenWidth, 0.016*screenWidth, 0.1467*screenWidth, 0.088*screenWidth)];
                namelabel.numberOfLines=0;
                namelabel.backgroundColor=[UIColor whiteColor];
                namelabel.text=qb.name;
                namelabel.textColor=[UIColor blackColor];
                namelabel.font=[UIFont systemFontOfSize:11.0];
                [duoBaoView addSubview:namelabel];
                float label_x=namelabel.frame.size.width+namelabel.frame.origin.x;
                float label_y=namelabel.frame.size.height+namelabel.frame.origin.y;
                
                duoBaoImageView1=[[UIImageView alloc]initWithFrame:CGRectMake(label_x+0.05067*screenWidth, 0.016*screenWidth, 0.2133*screenWidth, 0.128*screenWidth)];
                [duoBaoView addSubview:duoBaoImageView1];
                NSURL* imagePath = [NSURL URLWithString:qb.picName];
                //给一张默认图片，先使用默认图片，当图片加载完成后再替换
                [duoBaoImageView1 sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
                
                timeLabel1=[[UILabel alloc]initWithFrame:CGRectMake(0.04*screenWidth, label_y+0.03733*screenWidth, 0.266667*screenWidth, 0.029334*screenWidth)];
//                timeLabel1.backgroundColor=[UIColor redColor];
                NSString *str=[NSString stringWithFormat:@"0%@",qb.time];
                timeLabel1.text=@"1";
//                timeLabel1.text=str;
                timeLabel1.font=[UIFont systemFontOfSize:11.0];
                timeLabel1.backgroundColor=[UIColor whiteColor];
                timeLabel1.textColor=[UIColor colorWithRed:216/255.0 green:29/255.0 blue:96/255.0 alpha:1.0];
                [duoBaoView addSubview:timeLabel1];
                [labelArray addObject:timeLabel1];
//                float timeLabel2_x=timeLabel1.frame.origin.x+timeLabel1.frame.size.width;
//                UILabel *timeLabel2=[[UILabel alloc]initWithFrame:CGRectMake(timeLabel2_x, label_y+14, 5, 11)];
//                timeLabel2.text=@":";
//                timeLabel2.font=[UIFont systemFontOfSize:11.0];
//                timeLabel2.backgroundColor=[UIColor whiteColor];
//                timeLabel2.textColor=[UIColor colorWithRed:216/255.0 green:29/255.0 blue:96/255.0 alpha:1.0];
//                [duoBaoView addSubview:timeLabel2];
//                float timeLabel3_x=timeLabel2.frame.origin.x+timeLabel2.frame.size.width;
//                timeLabel3=[[UILabel alloc]initWithFrame:CGRectMake(timeLabel3_x, label_y+14, 15, 11)];
//                timeLabel3.text=@"00";
//                timeLabel3.font=[UIFont systemFontOfSize:11.0];
//                timeLabel3.backgroundColor=[UIColor whiteColor];
//                timeLabel3.textColor=[UIColor colorWithRed:216/255.0 green:29/255.0 blue:96/255.0 alpha:1.0];
//                [duoBaoView addSubview:timeLabel3];
            }
        }
        [[NSNotificationCenter defaultCenter]postNotificationName:@"updateRenQiTuiJian" object:nil];
        if (labelArray.count==4)
        {
//            self.timerNumber1=[timeArray[0] intValue];
//            self.timerNumber2=[timeArray[1] intValue];
//            self.timerNumber3=[timeArray[2] intValue];
//            self.timerNumber4=[timeArray[3] intValue];
            self.timerNumber1=180;
            self.timerNumber2=240;
            self.timerNumber3=120;
            self.timerNumber4=180;
            
            timer1=[WeakTimer scheduledTimerWithTimeInterval:1.0f block:^(id userInfo)
                        {
                            [self changeNum1];
                        } userInfo:nil repeats:YES];
            [[NSRunLoop currentRunLoop] addTimer:timer1 forMode:NSDefaultRunLoopMode];

            timer2=[WeakTimer scheduledTimerWithTimeInterval:1.0f block:^(id userInfo)
                    {
                        [self changeNum2];
                    } userInfo:nil repeats:YES];
            [[NSRunLoop currentRunLoop] addTimer:timer2 forMode:NSDefaultRunLoopMode];

            timer3=[WeakTimer scheduledTimerWithTimeInterval:1.0f block:^(id userInfo)
                    {
                        [self changeNum3];
                    } userInfo:nil repeats:YES];
            [[NSRunLoop currentRunLoop] addTimer:timer3 forMode:NSDefaultRunLoopMode];

            timer4=[WeakTimer scheduledTimerWithTimeInterval:1.0f block:^(id userInfo)
                    {
                        [self changeNum4];
                    } userInfo:nil repeats:YES];
            [[NSRunLoop currentRunLoop] addTimer:timer4 forMode:NSDefaultRunLoopMode];

        }
    }
}
-(void)changeNum1
{
    self.timerNumber1--;
    int num01=self.timerNumber1%60;
    int num00=self.timerNumber1/60;
    UILabel *label=labelArray[0];
    label.text=[NSString stringWithFormat:@"%d:%02d",num00,num01];
    if (self.timerNumber1==0)
    {
        //关闭定时器
        label.text=@"获奖人为初六";
        timer1.fireDate = [NSDate distantFuture];

    }
}

-(void)changeNum2
{
    self.timerNumber2--;
    int num01=self.timerNumber2%60;
    int num00=self.timerNumber2/60;
    UILabel *label=labelArray[1];
    label.text=[NSString stringWithFormat:@"%d:%02d",num00,num01];
    if (self.timerNumber2==0)
    {
        //关闭定时器
        label.text=@"获奖人为初六";
        timer2.fireDate = [NSDate distantFuture];
        
    }
}
-(void)changeNum3
{
    self.timerNumber3--;
    int num01=self.timerNumber3%60;
    int num00=self.timerNumber3/60;
    UILabel *label=labelArray[2];
    label.text=[NSString stringWithFormat:@"%d:%02d",num00,num01];
    if (self.timerNumber3==0)
    {
        //关闭定时器
        label.text=@"获奖人为初六";
        timer3.fireDate = [NSDate distantFuture];
        
    }
}
-(void)changeNum4
{
    self.timerNumber4--;
    int num01=self.timerNumber4%60;
    int num00=self.timerNumber4/60;
    UILabel *label=labelArray[3];
    label.text=[NSString stringWithFormat:@"%d:%02d",num00,num01];
    if (self.timerNumber4==0)
    {
        //关闭定时器
        label.text=@"获奖人为初六";
        timer4.fireDate = [NSDate distantFuture];
        
    }
}
-(void)updatePeopleOfPrice
{
    //网络请求
    NSString *urlString=[NSString stringWithFormat:@"http://112.74.114.1/Parenting/index.php/api/indiana/show"];
    HttpRequest *httpRequest=[HttpRequest sharedInstance];
    [httpRequest postWithURLString:urlString parameters:nil success:^(id responseObject)
     {
         id json1 = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         //获取数组
         json_Array1=[json1 objectForKey:@"data"];
         [self createDuoBaoView];
         //         NSLog(@"json1=%@",json1);
     } failure:^(NSError *error) {
         NSLog(@"error=%@",error);
     }];
}
-(void)nextToGoodsDetail:(UITapGestureRecognizer*)sender
{
    if (sender.view.tag==0)
    {
      yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=idArray[0];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
    }
    else if (sender.view.tag==1)
    {
        yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=idArray[1];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
    }
    else if (sender.view.tag==2)
    {
        yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=idArray[2];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
    }
    else if (sender.view.tag==3)
    {
        yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=idArray[3];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
    }
}
//添加人气推荐界面
-(void)updateRenQiTuiJian
{
    if (duoBaoViewArray.count>0)
    {
      UIView *view11=duoBaoViewArray[duoBaoViewArray.count-1];
        float view_y=view11.frame.origin.y+view11.frame.size.height;
        view22=[[UIView alloc]initWithFrame:CGRectMake(0, view_y, screenWidth, 0.064*screenWidth)];
        view22.backgroundColor=[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1];
        [self.backGroundView addSubview:view22];
        UILabel *renQiLabel=[[UILabel alloc]initWithFrame:CGRectMake(0.04*screenWidth, 0, 200, 0.064*screenWidth)];
       renQiLabel.text=@"人气推荐";
       renQiLabel.textColor=[UIColor blackColor];
        [view22 addSubview:renQiLabel];
        //网络请求
        NSString *urlString=[NSString stringWithFormat:@"http://112.74.114.1/parenting/index.php/api/Indiana/recommend"];
        HttpRequest *httpRequest=[HttpRequest sharedInstance];
        [httpRequest postWithURLString:urlString parameters:nil success:^(id responseObject)
         {
             id json2 = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
             //获取数组
             json_Array2=[json2 objectForKey:@"data"];
             [self createRenQiTuiJianView];
          //  NSLog(@"json2=%@",json2);
             
         } failure:^(NSError *error) {
             NSLog(@"error=%@",error);
         }];

    }
}
-(void)createRenQiTuiJianView
{
    if (json_Array2.count>0)
    {
        float view22_y=view22.frame.size.height+view22.frame.origin.y;
        renQi *rq=[renQi new];
        UIView *verticalLineView1=[[UIView alloc]initWithFrame:CGRectMake(screenWidth/2, view22_y+10, 2, 340)];
        verticalLineView1.backgroundColor=[UIColor colorWithRed:194/255.0 green:24/255.0 blue:91/255.0 alpha:0.8];
        [self.backGroundView addSubview:verticalLineView1];
        for (int i=0; i<2; i++)
        {
            for (int j=0; j<2; j++)
            {
                UIView * renQiView=[[UIView alloc]initWithFrame:CGRectMake(0+screenWidth/2*j+2*j, view22_y+180*i, screenWidth/2, 180)];
//                renQiView.backgroundColor=[UIColor orangeColor];
                //添加手势
                UITapGestureRecognizer *tap=[[UITapGestureRecognizer  alloc ] initWithTarget:self action : @selector (nextToGoodsDetail01:)];
                renQiView.userInteractionEnabled=YES;

                [renQiView addGestureRecognizer:tap];
                renQiView.tag=j+2*i;
                
                renQiView.backgroundColor=[UIColor whiteColor];
                [self.backGroundView addSubview:renQiView];
                //添加数组
                [renQiArray addObject:renQiView];
                
                rq.content=[json_Array2[j+i*2] objectForKey:@"content"];
                rq.renQiID=[json_Array2[j+i*2] objectForKey:@"id"];
                [renQiIDArray addObject:rq.renQiID];
                rq.invole=[json_Array2[j+i*2] objectForKey:@"invole"];
                rq.pic=[json_Array2[j+i*2] objectForKey:@"pic"];
                rq.sum=[json_Array2[j+i*2] objectForKey:@"sum"];
                UIImageView *renQiImageView2=[[UIImageView alloc]initWithFrame:CGRectMake(0.05067*screenWidth,0.02934*screenWidth, 140, 85)];
//                19,11, 140, 85
                [renQiView addSubview:renQiImageView2];
                NSURL* imagePath = [NSURL URLWithString:rq.pic];
                //给一张默认图片，先使用默认图片，当图片加载完成后再替换
                [renQiImageView2 sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"default"]];
                float detailLabel_y=renQiImageView2.frame.origin.y+renQiImageView2.frame.size.height;
                UILabel *detailLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, detailLabel_y+8, screenWidth/2-30, 12)];
//                detailLabel.backgroundColor=[UIColor orangeColor];
                detailLabel.text=rq.content;
                //字体居中
                detailLabel.textAlignment=NSTextAlignmentCenter;
                //字体大小
                detailLabel.font=[UIFont systemFontOfSize:12];
                [renQiView addSubview:detailLabel];
                
                float grayView_y=detailLabel.frame.origin.y+detailLabel.frame.size.height;
                UIView *grayView=[[UIView alloc]initWithFrame:CGRectMake(15, grayView_y+14, screenWidth/2-30, 3)];
                grayView.backgroundColor=[UIColor lightGrayColor];
                [renQiView addSubview:grayView];
                //红色的View
                float sumsum=[rq.sum intValue];
                float involeinvole=[rq.invole intValue];
                float redView_width=(screenWidth/2-30)/sumsum*involeinvole;
                UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(15, grayView_y+14, redView_width, 3)];
                redView.backgroundColor=[UIColor redColor];
                [renQiView addSubview:redView];
                float nowPeopleLabel_y=grayView.frame.origin.y+grayView.frame.size.height;
                //目前现有的人数
                UILabel*nowPeopleLabel1=[[UILabel alloc]initWithFrame:CGRectMake(0.04*screenWidth, nowPeopleLabel_y+5, 50, 11)];
                nowPeopleLabel1.text=@"目前人数:";
                nowPeopleLabel1.textColor=[UIColor blackColor];
                nowPeopleLabel1.font=[UIFont systemFontOfSize:10];
                [renQiView addSubview:nowPeopleLabel1];
                float nowPeopleLabel2_x=nowPeopleLabel1.frame.origin.x+nowPeopleLabel1.frame.size.width;
                nowPeopleLabel2=[[UILabel alloc]initWithFrame:CGRectMake(nowPeopleLabel2_x-5, nowPeopleLabel_y+5, 15, 11)];
                nowPeopleLabel2.text=rq.invole;
                nowPeopleLabel2.textColor=[UIColor blackColor];
                nowPeopleLabel2.font=[UIFont systemFontOfSize:10];
                [renQiView addSubview:nowPeopleLabel2];
                //总人数
                UILabel*totalPeopleLabel1=[[UILabel alloc]initWithFrame:CGRectMake(0.33067*screenWidth, nowPeopleLabel_y+5, 40, 11)];
                totalPeopleLabel1.text=@"总人数:";
                totalPeopleLabel1.textColor=[UIColor blackColor];
                totalPeopleLabel1.font=[UIFont systemFontOfSize:10];
                [renQiView addSubview:totalPeopleLabel1];
                
                float totalPeopleLabel2_x=totalPeopleLabel1.frame.size.width+totalPeopleLabel1.frame.origin.x;
                UILabel*totalPeopleLabel2=[[UILabel alloc]initWithFrame:CGRectMake(totalPeopleLabel2_x-5, nowPeopleLabel_y+5, 20, 11)];
                totalPeopleLabel2.text=rq.sum;
                totalPeopleLabel2.textColor=[UIColor blackColor];
                totalPeopleLabel2.font=[UIFont systemFontOfSize:10];
                [renQiView addSubview:totalPeopleLabel2];
            }
        }
        UIView *lastView=renQiArray[renQiArray.count-1];
        float last_y=lastView.frame.origin.y+lastView.frame.size.height;
        //backGroundScrollView的最终高度
        self.backGroundScrollView.contentSize=CGSizeMake(0,last_y+20);
    }
}
-(void)nextToGoodsDetail01:(UIGestureRecognizer*)sender
{
    if (sender.view.tag==0)
    {
        yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=renQiIDArray[0];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
  
    }
    else if (sender.view.tag==1)
    {
        yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=renQiIDArray[1];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
    }
    else if (sender.view.tag==2)
    {
        yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=renQiIDArray[2];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
    }
    else if (sender.view.tag==3)
    {
        yiYuanDuoBaoNextView *yydbn=[yiYuanDuoBaoNextView shardeManager];
        yydbn.whichViewToNext=0;
        yiYuanDuoBao *yydb=[yiYuanDuoBao shardeManager];
        yydb.idString=renQiIDArray[3];
        goodsDetailViewController *gdvc=[goodsDetailViewController new];
        [self.navigationController pushViewController:gdvc animated:YES];
        
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    [timer1 invalidate];
    [timer2 invalidate];
    [timer3 invalidate];
    [timer4 invalidate];
    [self.rotateTimer invalidate];
}

-(void) newsPrompt{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newsPromptSucceed) name:@"newsPrompt" object:nil];
    self.lyHomeModel = [[TCLYHomeModel alloc] init];
    TCLYUser * user = [[TCLYUser alloc] init];
    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys: user.userId,@"uid", nil];
    
    NSTimeInterval delayTime = 1.0f;
    //定时器间隔时间
    NSTimeInterval timeInterval = 30.0f;
    //创建子线程队列
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    //使用之前创建的队列来创建计时器
    _lytimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);//设置延时执行时间，delayTime为要延时的秒数
    dispatch_time_t startDelayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayTime * NSEC_PER_SEC));//设置计时器
    dispatch_source_set_timer(_lytimer, startDelayTime, timeInterval * NSEC_PER_SEC, 0.1 * NSEC_PER_SEC);
    dispatch_source_set_event_handler(_lytimer, ^{
        [self.lyHomeModel newsPromptParameter:dic];
    });//执行事件
    // 启动计时器
    dispatch_resume(_lytimer);
}

-(void)newsPromptSucceed{
    if (![self.lyHomeModel.newsPromptStr isEqual:@"-1"]) {
        int indexICareAbout=2;
        NSString *badgeValue= self.lyHomeModel.newsPromptStr;
        [[[[[self tabBarController] viewControllers] objectAtIndex: indexICareAbout] tabBarItem] setBadgeValue:badgeValue];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
//粉色
//timeLabel3.textColor=[UIColor colorWithRed:216/255.0 green:29/255.0 blue:96/255.0 alpha:1.0];


@end
